package com.smart.common.config.spring;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

/**
 * @author Administrator
 * Schedule线程配置文件
 */
@Configuration
public class ThreadConfig {
    @Bean
    public TaskScheduler taskScheduler() {
        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();

        scheduler.setWaitForTasksToCompleteOnShutdown(true);
        // 定时任务执行线程池核心线程数
        scheduler.setPoolSize(10);
        //设置线程名称前缀
        scheduler.setThreadNamePrefix("SMART-TASK-");
        // 是否开启取消删除任务功能
        scheduler.setRemoveOnCancelPolicy(true);
        return scheduler;
    }
}
